	PROGRAM NASPLTVER
C
C     NASTRAN(NASTPLT)-TO-VERSAPLOT TRANSLATOR.
C     PLOTS ARE GENERATED SEQUENTIALLY FROM THE NASTPLT FILE;
C     NONE ARE SKIPPED;
C     EACH IS SCALED TO FIT ON AN X=8.0 BY Y=10.5 INCH FRAME;
C     IN SCALING, THE ORIGINAL X/Y AXIS LENGTH RATIO IS MAINTAINED.
C
      CHARACTER*40 FILNAM
      LOGICAL LIBM
      DIMENSION IPLTREC(750)
      COMMON /NASTCOM/ ICMND,ICNTRL,IR,IS,IT,IU
      DATA MODEL/1200/
C
C     GET INPUT FILENAME & TYPE (VAX OR IBM)
	  CALL NAMTYP(FILNAM,LIBM)
C     OPEN PLOT FILE
	  OPEN(UNIT=13,NAME=FILNAM,TYPE='OLD',READONLY)
C     INITIALIZE PLOTTER
10	  TYPE 2000
	  ACCEPT *, MODEL
	  IF ((MODEL .NE. 1200) .AND. (MODEL .NE. 8236))  GOTO 10
	  ICHANGE = 1
	  CALL PLOTS(ICHANGE,0,0)
      DO 200 I=1,1000000
C	  GET NEXT NASTPLT RECORD
	      READ(13,1000,END=250) IPLTREC
C	  CONVERT IBM RECORD
	      IF (LIBM) CALL CNVIBM(IPLTREC)
	  DO 100 J=1,100
C	      GET JTH COMMAND FROM NASTPLT RECORD
		  CALL GETCMD(IPLTREC)
C	      EXECUTE COMMAND
		  IF (ICMND .EQ. 0)  CONTINUE
		  IF (ICMND .EQ. 1)  CALL BGNPLT(MODEL)
		  IF (ICMND .EQ. 2)  CONTINUE
		  IF (ICMND .EQ. 3)  CONTINUE
		  IF (ICMND .EQ. 4)  CALL DRWCHR
		  IF (ICMND .EQ. 5)  CALL DRWLIN
		  IF (ICMND .EQ. 6)  CALL DRWLIN
		  IF (ICMND .EQ. 14) CALL DRWCHR
		  IF (ICMND .EQ. 15) CALL DRWLIN
		  IF (ICMND .EQ. 16) CALL DRWLIN
100           CONTINUE
200	  CONTINUE
C     END OF PLOT FILE; CLOSE PLOTTER
250	  FACT = 1.0
	  CALL FACTOR(FACT)
	  CALL PLOT(0.0,0.0,999)
      STOP
C
1000  FORMAT(750A4)
2000  FORMAT(' ENTER VERSATEC MODEL NUMBER (1200/8236): ',$)
      END

      SUBROUTINE BGNPLT(MODEL)
      COMMON /NASTCOM/ NEWPLT,DUMM1,NUMPLT,MAXX,MAXY,DUMM2
C
C     TO START THE NEXT PLOT, THE VERSATEC PRINTER/PLOTTER MUST BE
C     ADVANCED TO THE NEXT PAGE, AND THE GENERAL SCALING FACTOR
C     MUST BE RECALCULATED TO SCALE THE PLOT TO THE AVAILABLE
C     8.0 BY 10.5 INCH PAGE ON THE MODEL 1200 VERSATEC, OR
C     TO USE THE FULL PLOT SIZE FOR THE MODEL 8236 VERSATEC.
C
C     ADVANCE TO NEXT PAGE
	  FACT = 1.0
	  CALL FACTOR(FACT)
	  CALL PLOT(0.0,0.0,-999)
C     CALCULATE NEW SCALING FACTOR
	  IF (MODEL .EQ. 8236)  THEN
C	      SET SCALING FACTOR FOR MODEL 8236 VERSATEC
	      CALL FACTOR(0.01)
	  ELSE IF (MODEL .EQ. 1200)  THEN
C	      CALCULATE SCALING FACTOR FOR MODEL 1200 VERSATEC
	      XFACT = 8.0 / FLOAT(MAXX)
	      YFACT = 10.5 / FLOAT(MAXY)
	      FACT = AMIN1(XFACT,YFACT)
	      CALL FACTOR(FACT)
	  ELSE
C	      INCORRECT MODEL SPECIFIED
	      STOP 'INVALID VERSATEC MODEL NUMBER'
	  END IF
      RETURN
      END

      SUBROUTINE CNVIBM(RECORD)
      INTEGER RECORD(750)
      BYTE BYTE(4), BTEMP(4)
      EQUIVALENCE (IWORD,BYTE(1)) , (ITEMP,BTEMP(1))
C
C     CONVERT FROM IBM FORMAT TO VAX FORMAT:
C     REVERSE THE ORDER OF THE BYTES IN EACH WORD OF THE RECORD
	  DO 100 I=1,750
	      ITEMP = RECORD(I)
	      BYTE(1) = BTEMP(4)
              BYTE(2) = BTEMP(3)
              BYTE(3) = BTEMP(2)
	      BYTE(4) = BTEMP(1)
              RECORD(I) = IWORD
100           CONTINUE
      RETURN
      END

      SUBROUTINE DRWCHR
C
C     TO TYPE A CHARACTER ON THE PLOT FRAME, THE NASTPLT CHARACTER
C     CODE (AN INTEGER VALUE BETWEEN 1 AND 52) IS USED AS A 
C     POINTER INTO A LIST OF VERSAPLOT CHARACTER CODES (THE ARRAY
C     CHRCOD), AND THE CHARACTER IS DRAWN USING THE VERSAPLOT
C     SUBROUTINE "SYMBOL".
C
      INTEGER CHRCOD(53)
      COMMON /NASTCOM/ ICMND,NSCODE,IX,IY
      DATA CHRCOD /48,49,50,51,52,53,54,55,56,57,
     *             65,66,67,68,69,70,71,72,73,74,75,76,77,
     *             78,79,80,81,82,83,84,85,86,87,88,89,90,
     *             40,41,43,45,42,47,61,46,44,36,39,32,
     *              1, 0, 5, 2,63 /
      DATA HEIGHT/8.0/, ANGLE/0.0/
C
C     USE "?" FOR AN ILLEGAL NASTPLT CHARACTER CODE
	  IF (NSCODE.LT.1 .OR. NSCODE.GT.52)  NSCODE = 53
C     PLOT THE CHARACTER
	  X = FLOAT(IX)
	  Y = FLOAT(IY)
C	  HEIGHT IS A SCALED 0.08 INCHES; ANGLE IS 0.0 DEGREES
	  CALL SYMBOL(X,Y,HEIGHT,CHRCOD(NSCODE),ANGLE,-1)
      RETURN
      END

      SUBROUTINE DRWLIN
      COMMON /NASTCOM/ LINE,NPEN,IX,IY,JX,JY
C
C     DRAW A LINE FROM (IX,IY) TO (JX,JY) WITH A LINE DENSITY
C     CORRESPONDING TO NPEN .
C
C     SET LINE DENSITY
	  CALL NEWPEN(NPEN)
C     MOVE PLOTTER POSITION TO BEGINNING (IX,IY) OF LINE
	  X = FLOAT(IX)
	  Y = FLOAT(IY)
	  CALL PLOT(X,Y,3)
C     DRAW LINE TO (JX,JY)
	  X = FLOAT(JX)
	  Y = FLOAT(JY)
	  CALL PLOT(X,Y,2)
      RETURN
      END

      SUBROUTINE GETCMD(PLTREC)
      IMPLICIT INTEGER (A-Z)
      DIMENSION PLTREC(750),Q(30),MASK(4)
      COMMON /NASTCOM/ CMND,CNTRL,R,S,T,U
      COMMON /RECPNT/ KWORD,KBYTE
C     EQUATE COMMAND INTEGERS TO MNEMONIC VARIABLES
          EQUIVALENCE
     *     (Q( 1),PC), (Q( 2),CI),
     *     (Q( 3),R4), (Q( 4),R3), (Q( 5),R2), (Q( 6),R1), (Q( 7),R0),
     *     (Q( 8),S4), (Q( 9),S3), (Q(10),S2), (Q(11),S1), (Q(12),S0),
     *     (Q(13),T4), (Q(14),T3), (Q(15),T2), (Q(16),T1), (Q(17),T0),
     *     (Q(18),U4), (Q(19),U3), (Q(20),U2), (Q(21),U1), (Q(22),U0)
C     INITIALIZE BYTE MASKS, AND PLTREC WORD & BYTE POINTERS
          DATA MASK(1) /'000000FF'X/ ,
     *         MASK(2) /'0000FF00'X/ ,
     *         MASK(3) /'00FF0000'X/ ,
     *         MASK(4) /'FF000000'X/
	  DATA KWORD /1/, KBYTE /4/
C
C     BREAK OUT 30 INTEGERS OF NEXT COMMAND
          DO 100 I=1,30
              Q(I) = IAND( PLTREC(KWORD) , MASK(KBYTE) )
              Q(I) = ISHFT( Q(I) , -8*(KBYTE-1) )
C             SET POINTERS TO GET NEXT BYTE
                  KBYTE = KBYTE - 1
                  IF (KBYTE .EQ. 0) KWORD = KWORD + 1
                  IF (KBYTE .EQ. 0) KBYTE = 4
		  IF (KWORD .EQ. 751) KWORD = 1
100           CONTINUE
C     CALCULATE CMND,CNTRL,R,S,T,&U
          CMND = PC
          CNTRL = CI
          R = R0 + 10*R1 + 100*R2 + 1000*R3 + 10000*R4
          S = S0 + 10*S1 + 100*S2 + 1000*S3 + 10000*S4
          T = T0 + 10*T1 + 100*T2 + 1000*T3 + 10000*T4
          U = U0 + 10*U1 + 100*U2 + 1000*U3 + 10000*U4
      RETURN
      END

      SUBROUTINE NAMTYP(FILNAM,LIBM)
      CHARACTER FILNAM*(*) , QFLAG*1
      LOGICAL LIBM
C
C     GET INPUT FILENAME
          TYPE 1000
	  ACCEPT 2000, FILNAM
C     IS THIS AN IBM FORMAT FILE ?
10	  TYPE 3000
	  ACCEPT 4000, QFLAG
	  IF (QFLAG .EQ. 'Y') THEN
	      LIBM = .TRUE.
          ELSE IF (QFLAG .EQ. 'N') THEN
              LIBM = .FALSE.
	  ELSE
C	      INPUT ERROR; TRY AGAIN
	      GOTO 10
	  ENDIF
      RETURN
C
1000  FORMAT(' ENTER NAME OF INPUT PLT2 FILE: ',$)
2000  FORMAT(A35)
3000  FORMAT(' CONVERT FILE FROM IBM FORMAT ? (Y OR N): ',$)
4000  FORMAT(A1)
      END
